<script setup lang="ts">
import { useRouter } from 'vue-router'

const router = useRouter()
// 接收父组件传过来的title，和right-text
const props = defineProps<{
  title?: string,
  rightText: string,
  back?: () => void
}>()
// 接受自定义事件
const emits = defineEmits<{
  (e:'click-right' ):void
}>()

const onClickLeft = () => {
  // TODO 点击左侧返回按钮
  if (props.back) {
    return props.back()
  } 
  // 判断能否返回上一页
  if (history.state.back) {
    router.back()
  } else {
    router.push('/')
  }
}
const onClickRight = () => {
  // TODO 点击右侧文字按钮
  emits('click-right')
}
</script>

<template>
  <van-nav-bar
    fixed
    left-arrow
    :title="title"
    :right-text="rightText"
    @click-left="onClickLeft"
    @click-right="onClickRight"
  ></van-nav-bar>
</template>

<style lang="scss" scoped>

</style>